import time
import json

from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse

from nginx.views import get_sys_info,get_sys_status
from views import is_auth

@login_required(login_url="/login/")
def view(request):
    sysinfo = get_sys_info()
    user = {
        'name':request.user,
        'date':time.time()
    }
    return render(request,'dashboard/view.html',{'sysinfo' : sysinfo, 'user' : user})

@is_auth
def get_status_info(request):
    context = {
        'flag':"Success",
        'context':{
            "sysstatus":get_sys_status()
        }
    }
    return HttpResponse(json.dumps(context))
